<?php
/* 前台用户表
* @Author: Jerry-chen
* @Date:   2014-07-07 13:13:24
* @Last Modified time: 2014-07-16 03:01:49
* @Last Modified by: Jerry-chen<uranusbill@163.com>
* @ Copyright (c) 2014 http://www.cooldreamer.com All rightsreserved.
*/
class UserModel extends Model
{
	
	public $table =  'user';
	//添加数据
    public function add_data($data)
   {
        	return $this->add($data);
    }
    //数据验证
    public function validate_index_login()
    {
		//获得用户提交验证用户名和密码 
		$username = Q('post.username');
		$password = Q('post.password','','md5');
		// p($password);
		// p($username);die;
		//获得数据库中的信息
		$userData = $this->where(array('username'=>$username))->find();
		if(!$userData||$username!=$userData['username']||$password!=$userData['password'])
		{

			$this->error('用户名或密码错误');

			return false;
		}
		//如果前面的都通过，证明用户名和密码都是对的

		return $userData;
    }
    public function get_all($where=null,$field=null)
    {
    	return $this->where($where)->field($field)->all();
    }
    /**
	 * [get_one 取得一个数据]
	 * @return [type] [description]
	 */
	public function get_one($where=null)
	{
		return $this->where($where)->find();
	}
}
?>
